package dl.bukkit.myststus.library.container;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.List;

public class ListContainer<E> {

    private final List<E> list;

    private Class<?>[] classes = null;

    public ListContainer(List<E> list) {
        this.list = list;
    }

    public ListContainer(List<E> list, Class<?>... classes) {
        this(list);
        this.classes = classes;
    }

    public final void register(Class<? extends E> cls, Object... objects) {
        try {
            Constructor<? extends E> constructor = classes == null ? cls.getDeclaredConstructor() : cls.getDeclaredConstructor(classes);
            constructor.setAccessible(true);
            list.add(constructor.newInstance(objects));
        }catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    public E get(int i) {
        return list.get(i);
    }

    public List<E> getList() {
        return list;
    }
}
